package com.qf.tenant.controller;

import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import com.qf.dto.SMSDto;
import com.qf.tenant.entity.Tenant;
import com.qf.tenant.service.TenantService;
import com.qf.utils.JWTUtil;
import com.qf.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
/**
 * <p>
 * 租户表 前端控制器
 * </p>
 *
 * @author 
 * @since 2023-10-26
 */
@RestController
@CrossOrigin
@RequestMapping("/tenant")
public class TenantController {

    @Autowired
    private TenantService tenantService;


    @GetMapping ("/verifyToken")
    public Result verifyToken(@RequestHeader("token") String token){
        try {
            JWTUtil.parseToken(token);
            return new Result(0,"valid token");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1,"invalid token");
        }
    }



    @RequestMapping("/login")
    public Result login(@RequestBody Tenant tenant) {

        return tenantService.login(tenant);
    }

    @PostMapping("/register")
    public  Result register(@RequestBody Tenant tenant){
        return tenantService.register(tenant);
    }

    @RequestMapping("/logout")
    public Result login() {
        return new Result(0,"success");
    }

    @RequestMapping("/sms")
    public Result sms(@RequestBody SMSDto smsDto) {
        return tenantService.sms(smsDto.getPhone());
    }

    @RequestMapping("/smsRegister")
    public Result smsRegister(@RequestBody SMSDto smsDto) {
        return tenantService.smsRegister(smsDto.getPhone());
    }

    @RequestMapping("/smslogin")
    public Result smslogin(@RequestBody SMSDto smsDto) {
        return tenantService.smslogin(smsDto);
    }
}

